package com.aaa.controller.mht;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.User;
import com.aaa.entity.mht.TMhtPlane;
import com.aaa.service.mht.TMhtPlaneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;

@RestController
@RequestMapping("tMhtPlane")
public class TMhtPlaneController {


        @Autowired
        private TMhtPlaneService tMhtPlaneService;


        // 查询所有的执行计划
        @GetMapping
        public LayData queryAll(MyPage myPage,TMhtPlane tMhtPlane){
            return new LayData(tMhtPlaneService.queryAll(myPage,tMhtPlane));
        }

        @PostMapping
        public LayData checkCode(TMhtPlane plane){
            return new LayData(tMhtPlaneService.selectPlane(plane));
        }
        @PostMapping("addPlane")
        public LayData addPlane(TMhtPlane plane, HttpSession session){
            System.out.println("==================================================="+plane);
            if (plane.getId()==null){
                User user1=(User) session.getAttribute("user");
                plane.setCreatetime(new Date());
                plane.setUid(user1.getId());
                System.out.println(plane);
                return new LayData(tMhtPlaneService.insertPlane(plane));
            }else {
                return new LayData(tMhtPlaneService.updatePlane(plane));
            }

        }

        @GetMapping("getByCode")
        public LayData queryByQyCode(TMhtPlane tMhtPlane){
            return new LayData(tMhtPlaneService.queryByQyCode(tMhtPlane));
        }
   @RequestMapping("updUserStatus")
    public LayData updUserStatus(TMhtPlane tMhtPlane){
       Boolean i = tMhtPlaneService.updUserStatus(tMhtPlane);
        return new LayData(i);
    }

    }

